#定义一个空字典
my_dict1 = {}
my_dict2 = dict()


#定义字典
my_dict3 = {"王力宏": 33, "周杰伦": 99, "刘德华": 67}
print(f"字典1的内容是: {my_dict1},其类型是{type(my_dict1)}")
print(f"字典2的内容是: {my_dict2},其类型是{type(my_dict2)}")
print(f"字典3的内容是: {my_dict3},其类型是{type(my_dict3)}")

#定义重复Key的字典
my_dict4 = {"王力宏": 33, "王力宏": 55, "周杰伦": 99, "刘德华": 67}
print(f"字典4的内容是: {my_dict4},其类型是{type(my_dict4)}")

#从字典中基于Key获取Value
my_dict3 = {"王力宏": 33, "周杰伦": 99, "刘德华": 67}
score = my_dict3["王力宏"]
print(f"王力宏的分数是: {score}")
#定义嵌套字典
stu_score_dict = {"周杰伦":{"语文": 77, "数学": 88, "英语": 99},
                  "王力宏":{"语文": 25, "数学": 65, "英语": 85},
                  "蔡徐坤":{"语文": 32, "数学": 58, "英语": 77}}
print(f"学生的考试信息是: {stu_score_dict}")

#从嵌套字典中获取数据
score = stu_score_dict["周杰伦"]["语文"]
print(f"周杰伦的语文信息: {score}")

"""
字典的常用操作
"""

#新增元素
my_dict3 = {"王力宏": 33, "周杰伦": 99, "刘德华": 67}
my_dict3["赵磊"] = 35
print(f"新增一个元素后的字典: {my_dict3}")
#更新元素
my_dict3["周杰伦"] = 67
print(f"更新元素后的字典,结果是: {my_dict3}")
#删除元素
score = my_dict3.pop("周杰伦")
print(f"字典中被移除了一个元素,结果:{my_dict3}, 周杰伦的考试分数是: {score}")
#清空元素
my_dict3.clear()
print(f"字典被清空了: {my_dict3}")
#获取全部的key
my_dict3 = {"王力宏": 33, "周杰伦": 99, "刘德华": 67}
keys = my_dict3.keys()
print(f"字典的全部key是:{keys}")
#遍历字典
#方式1:通过获取全部的key来完成遍历
for key in keys:
    print(f"字典的key是:{key}")
    print(f"字典的value是: {my_dict3[key]}")
#方式2:直接通过字典进行for循环,每一次循环都是直接得到key
for key in my_dict3:
    print(f"2字典的key是:{key}")
    print(f"2字典的value是: {my_dict3[key]}")
#统计字典内的数量
num = len(my_dict3)
print(f"字典中的元素数量是: {num}")

"""
练习:
    升职加薪
    对所有级别为1级的员工,级别上升1级,薪水增加1000元
"""
#定义字典
my_dict = {"王力宏":{"部门":"科技部","工资":3000,"级别":1},
           "周杰伦":{"部门":"市场部","工资":5000,"级别":2},
           "林俊杰":{"部门":"市场部","工资":7000,"级别":3},
           "张学友":{"部门":"科技部","工资":4000,"级别":1},
           "刘德华":{"部门":"市场部","工资":6000,"级别":2}}
print(f"全体员工当前信息如下: {my_dict} ")
#通过for循环进行遍历
for name in my_dict:#注意这里遍历的是key
    if my_dict[name]["级别"] == 1:
        my_dict[name]["级别"] += 1
        my_dict[name]["工资"] += 1000
    print(f"全体员工级别为1的员工完成升职加薪操作,操作后:{my_dict[name]}")




